package com.pain.scaffold.admin.service.sms;

import cn.hutool.core.date.DateUtil;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody;
import com.aliyun.teaopenapi.models.Config;

import java.util.Date;

public class SmsService {
    public static void main(String[] args) throws Exception {
        //以下2个参数为阿里云短信配置的模板变量
        String date = DateUtil.formatDate(new Date());
        String serviceName = "服务名";
        Config config = new Config();
        config.setAccessKeyId("key");
        config.setAccessKeySecret("secret");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers("phone")
                .setSignName("signName")
                .setTemplateCode("templateCode")
                .setTemplateParam("{\"serviceName\":\"" + serviceName + "\",\"date\":\"" + date + "\"}");
        SendSmsResponse sendSmsResponse = new Client(config).sendSms(sendSmsRequest);
        SendSmsResponseBody body = sendSmsResponse.getBody();
        //返回消息
        System.out.println(body.getMessage());
    }
}
